import domain.Product;
import domain.Users;
import service.ProductService;
import service.UsersService;
import tools.OrderTools;

import java.util.List;
import java.util.Scanner;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println(OrderTools.createOrderCode());
        System.out.println("欢迎进入山科超市");
        System.out.println("1.用户注册");
        System.out.println("2.用户登录");
        System.out.println("3.查询全部产品");
        System.out.println("请选择:");
        Scanner scanner = new Scanner(System.in);
        String msg = scanner.nextLine();
        switch (Integer.parseInt(msg)){
            case 1:
                System.out.println("待建设中");
                break;
            case 2:
                System.out.println("请输入账号和密码,以逗号分隔");
                msg = scanner.nextLine();
                String[] arr = msg.split(",");
                //调用业务逻辑
                UsersService usersService = new UsersService();
                Users users = usersService.login(arr[0],arr[1]);
                if(users != null){
                    System.out.println("登录成功,欢迎您："+users.getUname());
                }else{
                    System.out.println("登录失败！");
                }
                break;
            case 3:
                ProductService ps = new ProductService();
                List<Product> data = ps.findByAll();
                for (Product p : data) {
                    System.out.println("产品id:" + p.getPid()
                                      +",产品code:" + p.getPcode()
                                      +",产品名称：" + p.getPname()
                                      +",产品类型：" + p.getPtid().getPtname()
                                      +",产品价格：" + p.getPprice());
                }
                break;
            default:
                System.out.println("对不起，输入错误！");
        }
    }
}
